package com.nick.sscplan.util;

import java.util.ArrayList;
import java.util.List;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import com.nick.sscplan.bean.SscInfo;

import android.content.Context;
import android.util.Log;

public class Ssc_XmlHandler extends DefaultHandler{
    
    
    private static final String TAG = "ssc_plan";
    
    private List<SscInfo> sscInfos = new ArrayList<SscInfo>();
    
    
    public Ssc_XmlHandler() {
    }
    

    public void startDocument() throws SAXException {
        super.startDocument();
    }
    
    
    public void endDocument() throws SAXException {
        super.endDocument();
    }
    
    
    public void startElement(String uri, String localName, String qName,
            Attributes attributes) throws SAXException {
        super.startElement(uri, localName, qName, attributes);
        if (localName.equals("row")) {
            String time = attributes.getValue("opentime");
            String num = attributes.getValue("opencode");
//            Log.d(TAG, "num = " + num);
//            Log.d(TAG, "data1 = " + Integer.parseInt(num.substring(0 , 1)));
//            Log.d(TAG, "data2 = " + Integer.parseInt(num.substring(2 , 3)));
            String issue = attributes.getValue("expect");
            SscInfo sscInfo = new SscInfo();
            sscInfo.setIssue(Long.parseLong(issue));
            sscInfo.setData1(Integer.parseInt(num.substring(0, 1))) ;
            sscInfo.setData2(Integer.parseInt(num.substring(2, 3))) ;
            sscInfo.setData3(Integer.parseInt(num.substring(4, 5))) ;
            sscInfo.setData4(Integer.parseInt(num.substring(6, 7))) ;
            sscInfo.setData5(Integer.parseInt(num.substring(8, 9))) ;
            sscInfo.setOpentime(time);
            sscInfos.add(sscInfo);
        }
    }
    
    public void endElement(String uri, String localName, String qName)
            throws SAXException {
        super.endElement(uri, localName, qName);
        if (localName.equals("row")) {
            
        }
    }
    
    public List<SscInfo> getSscInfo(){
        return sscInfos;
    }
}
